
/**
 * 打开thickbox
 * @param h
 * @param w
 * @return
 */
function open_thickbox(html,h,w){
	    createBox();
        if(typeof h == 'undefined'){
              h = 350;
        }
        if(typeof w == 'undefined'){
            w = 550;
        }
        if(typeof html == 'undefined'){
        	html = 'html为空';
        }
        try{
        var alt = "#TB_inline?height="+h+"&width="+w+"&inlineId=show_div";
        $("#common_thickbox_input").attr('alt',alt);
        $("#show_div_content").html(html);
        $("#common_thickbox_input").trigger('click');
        }catch(e){
        	alert(e.message);
        }
    }
function open_thickbox_textarea(html,h,w){
    createBox();
    if(typeof h == 'undefined'){
          h = 350;
    }
    if(typeof w == 'undefined'){
        w = 550;
    }
    if(typeof html == 'undefined'){
    	html = 'html为空';
    }
    var alt = "#TB_inline?height="+h+"&width="+w+"&inlineId=show_div";
    $("#common_thickbox_input").attr('alt',alt);
    $("#show_div_content").html("<textarea cols='120' rows='30'></textarea>");
    $("#show_div_content > textarea").val(html);
    
    $("#common_thickbox_input").trigger('click');
}

function createBox(){
	
	if(typeof $("#common_thickbox").val() == 'undefined'){
		var f = '';
			f+='<frame name="thickbox" scrolling="no">';
			f+='<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
			f+='<html>';
			f+='<head>';
			f+='<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
			f+='<link href="/res/lib/thickbox/common.css" rel="stylesheet" type="text/css" />';
			f+='<link href="/res/lib/thickbox/thickbox.css" rel="stylesheet" type="text/css" />';
			f+='<script type="text/javascript" src="/res/js/lib/jquery.js"></script>';
			f+='<script type="text/javascript" src="/res/lib/thickbox/thickbox-compressed.js"></script>';
			f+='</head>';
			f+='<body>';
			f+='<input type="hidden" id="common_thickbox" value="1" />';
			f+='<input type="button" style="display:none;"'; 
			f+=' id="common_thickbox_input"';
			f+=' class="thickbox" ';
			f+=' value="专用弹窗" ';
			f+=' alt="#TB_inline?height=250&width=500&inlineId=show_div"'; 
			f+=' title="专用弹窗"/>';
			f+='<div id="show_div" style="display:none;">';
			f+='<div id="show_div_content"></div>';
			f+='</div>';
			f+='</body>';
			f+='</html>';
			f+='</frame>';
		$("body").append(f);
	}
	
}
$(document).ready(function(){
	createBox();
});

/**
 * 通用ajax方法，自动日志，自动thickbox提示
 * @param name
 * @param uri
 * @param log
 * @returns {Boolean}
 */
function ajax_thickbox_json(data,uri,textarea,log){
	 if (typeof data == 'undefined' || typeof uri == 'undefined'){
		 alert('ajax_thickbox function need args : data and uri');
		 return false;
	 }
	 if (typeof log == 'undefined'){
		 log = 'undefined_ajax_thickbox';
	 }
	 if (typeof textarea == 'undefined'){
		 textarea = 1;
	 }
	 data = encodeURIComponent(data);
	 log = encodeURIComponent(log);
	 $.ajax({
         url:uri,
         method:'post',
         data:'sys_ajax=1&sys_debug_log='+log+'&data='+data+'&cache='+Math.random(),
         dataType:'json',
         success:function(json){
       	  if(json.success){
	       		  if (textarea){
	       			  open_thickbox_textarea(json.msg);
	       		  }else {
	       			  open_thickbox(json.msg);
	       		  }
                }else {
                     alert(json.msg);
                     }
          },
          error:function (e){
            alert(e.responseText);
          }
         
       });
	
}

